package controller;

import com.alibaba.fastjson.JSON;
import common.result.Result;
import common.result.ResultUtils;
import common.util.PageBean;
import model.dto.RegistryDto;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import service.RegistryService;

import java.util.HashMap;
import java.util.Map;

/**
 * @className: controller.RegistryController
 * @author: Xia
 * @create: 2023-03-15 13:57
 */
@Controller
@RequestMapping("/api/register")
public class RegisterController {
    @Autowired
    private RegistryService service;
    @RequestMapping("registerAdd")
    public String toRegisterAdd(){
        return "registerAdd";
    }
    @RequestMapping("registerList")
    public String RegisterList(String patientIdCard, String departmentName, String userName, Integer status,
                               @RequestParam(name = "pageNo" , defaultValue = "1") Integer index, Model model){
        PageBean<RegistryDto> page = service.page(patientIdCard, departmentName, userName, status, index);
        model.addAttribute("pages",page);
        model.addAttribute("queryIdCard",patientIdCard);
        model.addAttribute("queryDepartmentId",departmentName);
        model.addAttribute("queryDoctorId",userName);
        model.addAttribute("queryStatus",status);
        return "registerList";
    }


    public String RegisterAdd(){

        return "";
    }
    @ResponseBody
    @RequestMapping("/createFee/{isMedicare}")
    public Result getRegistryById(@PathVariable("isMedicare") Integer isMedicare){
        Result result;
        Map<String, Integer> map = new HashMap<>();

        if (isMedicare==1){
            map.put("fee",49);
            map.put("medicareFee",48);
            map.put("payFee",1);
            result = ResultUtils.returnDataSuccess(map);
        }else {
            map.put("fee",49);
            map.put("medicareFee",10);
            map.put("payFee",39);
            result = ResultUtils.returnDataSuccess(map);
        }
        return result;
    }
}
